package com.walle.sonar.export.report.api.lines;

import java.util.HashMap;

import com.jayway.jsonpath.ReadContext;
import com.jayway.jsonpath.TypeRef;
import com.walle.ak47.commons.utils.HttpClientPool;
import com.walle.ak47.commons.utils._JsonPath;

public class GetLineInfo {

	public String getCodeLine(String key, int line) {
		 
		String _url = "http://127.0.0.1:9000/api/sources/lines?key="+key+"&from="+line+"&to="+line ;
		HashMap<String, Object> _headers = new HashMap<String, Object>();
		String result = HttpClientPool.httpGet(_url, _headers);
		
		ReadContext parse = _JsonPath.parse(result);
		String read = _JsonPath.read(parse, "$.sources[0].code", new TypeRef<String>() {}  );
		
		return read ;
	}
	
	public static void main(String[] args) {
		
		GetLineInfo getLineInfo = new GetLineInfo() ;
		String codeLine = getLineInfo.getCodeLine("zentao__:8e9eac58130609153f84d9fa8767afd949e6fb74:zentao/bin/php/backup.php",4);
		System.err.println(codeLine);
		
	}
}
